package com.sky.mapper;

import com.sky.anno.MyAutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    List<Category> page(CategoryPageQueryDTO categoryPageQueryDTO);

    @MyAutoFill(OperationType.INSERT)
    @Insert("insert into category values (default,#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void add(Category category);

    @MyAutoFill(OperationType.UPDATE)
    @Update("update category set status = #{status} where id = #{id}")
    void changeStatus(Integer status, Long id);

    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);

    @MyAutoFill(OperationType.UPDATE)
    void update(CategoryDTO categoryDTO);

    @Select("select * from category where type = #{type}")
    List<CategoryDTO> findByType(Integer type);
}
